{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a1ec0967-0b49-4460-84fd-bded80823b7e",
   "metadata": {},
   "source": [
    "将lfwc中的数据划分成训练集和测试集  \n",
    "每个人的文件夹下面提出三分之一作为测试集  \n",
    "来验证对齐效果对于识别准确率的影响"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b6187eb8-704e-4a37-b3da-f09d646ecccd",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "import glob\n",
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b067166d-b82a-40ae-a4a4-51cc0f27f884",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'lfwc_processed/Adrien_Brody'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "file_list = glob.glob('lfwc/*')\n",
    "file_list = sorted(file_list)\n",
    "file_list[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "34bb129b-5df5-4a3d-b68b-cc943cc281cf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "lfwc_processed/Amelie_Mauresmo/Amelie_Mauresmo_0013.jpg\n",
      "lfwc_processed/Amelie_Mauresmo/Amelie_Mauresmo_0021.jpg\n",
      "lfwc_processed/Amelie_Mauresmo/Amelie_Mauresmo_0005.jpg\n",
      "lfwc_processed/Amelie_Mauresmo/Amelie_Mauresmo_0003.jpg\n",
      "lfwc_processed/Amelie_Mauresmo/Amelie_Mauresmo_0006.jpg\n",
      "lfwc_processed/Amelie_Mauresmo/Amelie_Mauresmo_0011.jpg\n",
      "lfwc_processed/Amelie_Mauresmo/Amelie_Mauresmo_0020.jpg\n",
      "\n",
      "\n",
      "Amelie_Mauresmo\n",
      "Amelie_Mauresmo\n",
      "Amelie_Mauresmo\n",
      "Amelie_Mauresmo\n",
      "Amelie_Mauresmo\n",
      "Amelie_Mauresmo\n",
      "Amelie_Mauresmo\n",
      "Amelie_Mauresmo\n",
      "Amelie_Mauresmo\n",
      "Amelie_Mauresmo\n",
      "Amelie_Mauresmo\n",
      "Amelie_Mauresmo\n",
      "Amelie_Mauresmo\n",
      "Amelie_Mauresmo\n"
     ]
    }
   ],
   "source": [
    "item = file_list[9] + '/*'\n",
    "image_list = glob.glob(item)\n",
    "random.shuffle(image_list)\n",
    "test_list = image_list[:len(image_list)//3]\n",
    "train_list = image_list[len(image_list)//3:]\n",
    "for item in test_list:\n",
    "    print(item)\n",
    "print('\\n')\n",
    "for item in train_list:\n",
    "    print(item.split('/')[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "c6a4d7fa-8899-425b-9df5-7e4b143db16b",
   "metadata": {},
   "outputs": [],
   "source": [
    "for item in file_list:\n",
    "    file_name = item.split('/')[1]\n",
    "    os.system('mkdir test/'+file_name)\n",
    "    os.system('mkdir train/'+file_name)\n",
    "\n",
    "    image_list = glob.glob(item+ '/*')\n",
    "    random.shuffle(image_list)\n",
    "    test_list = image_list[:len(image_list)//3]\n",
    "    train_list = image_list[len(image_list)//3:]\n",
    "    \n",
    "    for item in test_list:\n",
    "        os.system('cp '+item+' test/'+file_name)\n",
    "    for item in train_list:\n",
    "        os.system('cp '+item+' train/'+file_name)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
